
//获取购物车的数据，再传到本地存储

function addPro () {
	var imgsrc = $(".pro_img").children("img").attr("src");
	if(imgsrc == undefined){
		imgsrc = "images/shop_1.jpg";
	}
	var proname = $("#pro_name").text();
	var pro_price = $("#pro_price").text();
	var pro_num = $(".buy_num>input").val();
	var pro_total = parseFloat($("#pro_price").text())*pro_num;

	var product = {
		imgsrc:imgsrc,
		proname:proname,
		pro_price:pro_price,
		pro_num:pro_num,
		pro_total:pro_total
	}
	
	addCar(product);
	
	shopcatnum();
}

function addPay () {
	var imgsrc = $(".pro_img").children("img").attr("src");
	if(imgsrc == undefined){
		imgsrc = "images/shop_1.jpg";
	}
	var proname = $("#pro_name").text();
	var pro_price = $("#pro_price").text();
	var pro_num = $(".buy_num>input").val();
	var pro_total = parseFloat($("#pro_price").text())*pro_num;

	var product = [{
		imgsrc:imgsrc,
		proname:proname,
		pro_price:pro_price,
		pro_num:pro_num,
		pro_total:pro_total
	}]
	
	localStorage.setItem("buyData",JSON.stringify(product));
	location.href = "confirm_order.html";
}

//获取购物车的数据，再传到支付页的本地存储

//更新产品详情数据
$(function(){
	function loadProdata(){
		var proData = JSON.parse(localStorage.getItem("pro"));
		if (proData) {
			$("#preview img").attr("src",proData.imgsrc) ;
			$(".pro_img img").attr("src",proData.imgsrc) ;
			$("#pro_price").text(proData.price);
			$("#pro_name").text(proData.pro_name);
		}
	}
	loadProdata();
})

function Toggle(event){
	var that = event.target;
	$(".details").toggle();
	$(".comment").toggle();
	$(that).addClass("on").parent().siblings().children().removeClass("on")
}

$(function(){
	$(".mark li").click(function(){
		var src = $(this).find("img").attr("src");console.log(src);
		var index = $(this).index();
		for (var i=0;i<=index;i++) {
			$(this).parent(".mark").find("img").eq(i).attr("src","images/star-1.png")
		}
		for (var j=index+1;j<6;j++) {
			$(this).parent(".mark").find("img").eq(j).attr("src","images/xing3.png")
		}
	})
})
